#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int MAXN = 2e5+5;
const int MAXM = 1e6+5;
int T;
int n;
int a[MAXN];
int cnt[MAXM];

inline void solve()
{
	memset(a,0,sizeof(a));
	memset(cnt,0,sizeof(cnt));
	scanf("%d",&n);
	int maxn = 0;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		cnt[a[i]]++;
		maxn = max(maxn,a[i]);
	}
	long long ans = 0;
	for(int i=1;i<=maxn;++i)
	{
		//~ cout << "***" << i << " " << cnt[i]-1 << endl;
		ans += 1ll*i*max(0,cnt[i]-1);
	}
	printf("%lld\n",ans);
}

int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%d",&T);
	while(T--)
		solve();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
